package com.sdleyou.treepro.business.api.pay;

import com.sdleyou.treepro.common.model.dto.RechargeDto;
import com.sdleyou.treepro.common.model.utils.ResultVOUtil;
import com.sdleyou.treepro.common.model.vo.OrderVO;
import com.sdleyou.treepro.common.model.vo.ResultVO;
import com.sdleyou.treepro.common.service.OrderManager;
import com.sdleyou.treepro.common.service.PayService;
import com.sdleyou.treepro.common.utils.IdGen;
import com.sdleyou.treepro.system.payment.AppletPayUtil;
import com.sdleyou.treepro.system.version.ApiVersion;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/")
public class PayController {

    @Autowired
    private PayService payService;

    @Autowired
    private OrderManager orderManager;

    @ApiOperation(value = "创建订单", notes = "创建订单")
    @ApiVersion(1)
    @PostMapping("/{version}/pay")
    public Object order(@RequestParam("user_id") String userId,
                        @RequestParam("tree_id") String treeId,
                        @RequestParam("num") Integer num) throws Exception {
        /**
         微信小程序支付
         */
        //创建订单
        OrderVO orderVO = orderManager.addOrder(userId, treeId, num);
        return ResultVOUtil.success(payService.unifiedOrder(orderVO.getOrderSn(), BigDecimal.valueOf(orderVO.getOrderAmount()), userId));
    }
}